﻿using MetroDataApi.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace MetroDataApi.Controllers.DataQueryTable
{
    public class DataContentItem
    {
        [Display(Name = "date")]
        public DateTime Date { get; set; }

        [Display(Name = "number")]
        public int Count { get; set; }

        public string Format(string paras, string split = ",")
        {
            var strs = paras.Split(',');
            var primaryPropList = this.GetType().GetProperties().
              Where(p => p.IsDefined(typeof(DisplayAttribute), false));
            var l = new List<string>();
            foreach (var s in strs)
            {
                var t = primaryPropList.SingleOrDefault(p => p.GetCustomAttributes(typeof(DisplayAttribute), true).
                               Cast<DisplayAttribute>().SingleOrDefault().Name == s);
                if (t == null) continue;
                if (t.PropertyType == typeof(DateTime))
                {
                    l.Add(Convert.ToDateTime(t.GetValue(this, null)).ToString("yyyy-MM-dd"));
                }
                else
                {
                    l.Add(t.GetValue(this, null).ToString());
                }
            }
            return string.Join(split, l.ToArray());
        }
    }

    public class DataContent
    {


        public string Title { get; set; }

        private int count = 0;
        public int Count
        {
            get { return this.Items.Count; }
            set
            {
                this.count = value;
            }
        }
        public string MonitorType { get; set; }
        public string Location { get; set; }
        public List<DataContentItem> Items { get; set; }

        public DataContent(string m = "", string l = "")
        {
            this.Count = 0;

            this.MonitorType = m;
            this.Location = l;
            this.Title = l + "-" + m;
        }
    }

    public class RecentTableChanges
    {
        public string lastTime { get; set; }
        public IEnumerable<result> lastValues { get; set; }

        public string curTime { get; set; }
        public IEnumerable<result> curValues { get; set; }


        public string originTime { get; set; }
        public IEnumerable<result> originValues { get; set; }


        public RecentTableChanges()
        {
            this.lastValues = new List<result>();
            this.curValues = new List<result>();
            this.originValues = new List<result>();
        }
    }
}